package com.yunji.base.dao.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.yunji.base.bo.ManagerUpdateBO;
import com.yunji.base.dao.IManagerDao;
import com.yunji.base.domain.ManagerDO;
import com.yunji.base.mapper.IManagerMapper;
import com.yunji.common.base.BaseDaoImpl;
import com.yunji.common.utils.bean.BeanUtils;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author : peter-zhu
 * @date : 2024/12/11 15:49
 * @description : TODO
 **/
@Repository
public class ManagerDaoImpl extends BaseDaoImpl<IManagerMapper, ManagerDO> implements IManagerDao {

    @Override
    public ManagerDO getByUserId(Long managerId) {
        return lambdaQuery().eq(ManagerDO::getManagerId, managerId).one();
    }

    @Override
    public List<ManagerDO> listByUserIds(List<Long> userIds) {
        return lambdaQuery().in(ManagerDO::getManagerId, userIds).list();
    }

    @Override
    public boolean updateByManger(ManagerUpdateBO bo) {
        return baseMapper.update(new LambdaUpdateWrapper<ManagerDO>()
                .set(BeanUtils.isNotNull(bo.getScale()), ManagerDO::getScale,bo.getScale())
                .set(BeanUtils.isNotNull(bo.getScaleType()), ManagerDO::getScaleType,bo.getScaleType())
                .set(BeanUtils.isNotNull(bo.getCustomPrice()), ManagerDO::getCustomPrice,bo.getCustomPrice())
                .eq(ManagerDO::getManagerId,bo.getManagerId())) > 0;
    }

    @Override
    public boolean customPriceByManagerId(Long managerId, Integer customPrice) {
        return update(new LambdaUpdateWrapper<ManagerDO>()
                .set(ManagerDO::getCustomPrice,customPrice)
                .eq(ManagerDO::getManagerId,managerId));
    }

    @Override
    public List<ManagerDO> listByAgentIds(List<Long> agentIds) {
        return lambdaQuery().in(ManagerDO::getAgentId, agentIds).list();
    }

    @Override
    public boolean updateScaleByMangerId(Long managerId, BigDecimal scale) {
        return lambdaUpdate().eq(ManagerDO::getManagerId, managerId).set(ManagerDO::getScale, scale).update();
    }

    @Override
    public boolean deleteByUserId(List<Long> userIds) {
        return lambdaUpdate().in(ManagerDO::getManagerId, userIds).remove();
    }

    @Override
    public boolean deleteByAgentId(List<Long> agentId) {
        return lambdaUpdate().in(ManagerDO::getAgentId, agentId).remove();
    }
}
